﻿using MaterialDesignThemes.Wpf.Transitions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace SPW.Component.Helpers
{
    public static class AnimationHelper
    {
        //public static void Slide(this FrameworkElement element, TransitionEffectKindEx effectKind, double milliseconds, Action callBack)
        //{
        //    if (element is ITransitionEffectSubject) throw new ArgumentNullException(nameof(effectSubject));

        //    Storyboard sb = new Storyboard();

        //    Timeline timeline = null;
        //    DependencyProperty property = null;
        //    DependencyObject target = null;
        //    switch (effectKind)
        //    {
        //        case TransitionEffectKindEx.SlideInFromLeft:
        //            {
        //                timeline = CreateSlide(-300, 0, (element as ITransitionEffectSubject).Offset);
        //                property = TranslateTransform.XProperty;
        //                targetName = effectSubject.TranslateTransformName;
        //            }
        //            break;
        //        case TransitionEffectKindEx.SlideOutFromLeft:
        //            {
        //                timeline = CreateSlide(0, -300, (element as ITransitionEffectSubject).Offset);
        //                property = TranslateTransform.XProperty;
        //                targetName = effectSubject.TranslateTransformName;
        //            }
        //            break;
        //    }
        //    sb.Children.Add(timeline);
        //    Storyboard.SetTarget(timeline, element);
        //    Storyboard.SetTargetProperty(timeline, new PropertyPath("(Canvas.Top)"));
        //    element.BeginAnimation(TranslateTransform.XProperty, da);
        //}


        //private static Timeline CreateSlide(double from, double to, TimeSpan initialOffset)
        //{
        //    var zeroFrame = new DiscreteDoubleKeyFrame(from);
        //    var startFrame = new DiscreteDoubleKeyFrame(from, initialOffset + TimeSpan.Zero);
        //    var endFrame = new EasingDoubleKeyFrame(to, initialOffset + TimeSpan.Zero + TimeSpan.FromMilliseconds(400)) { EasingFunction = new SineEase() };
        //    var slideAnimation = new DoubleAnimationUsingKeyFrames();
        //    slideAnimation.KeyFrames.Add(zeroFrame);
        //    slideAnimation.KeyFrames.Add(startFrame);
        //    slideAnimation.KeyFrames.Add(endFrame);

        //    return slideAnimation;
        //}
    }
}
